// PROGRAMA : SCRP110A
// SISTEMA : SISP - SISTEMA DE INFORMACOES DE SEGURANCA PUBLICA
// IDENTIFICACAO CRIMINAL
// BIBLIOTECA : SISP
// CLIENTE : GEJUSPC - GERENCIA DE ESTADO DA JUSTICA, SEGURANCA
// PUBLICA E CIDADANIA / INSTITUTO DE IDENT.
// OBJETIVO : INCLUSAO DA FICHA DE INDICE CRIMINAL
// PROGRAMADOR: JOSE ANTONIO COELHO
// DATA : 29 DE JULHO DE 1997
// ALTERACAO : 04/11/1999 TELA E DATA (N6) PARA (N8)
// POR SOLON
// ALTERACAO
// FONETIZACAO DO NOME, NOME DA MAE, NOME DO PAI
// E ALCUNHAS DO ARQUIVO SIC-CADASTRO.
// AUTOR: CARLOS HENRIQUE DATA: 16/11/1998
// GERACAO AUTOMATICA PELO SISTEMA DO REG. GERAL
// AUTOR: SOLON MIRANDA DATA: 11/02/1999
package br.com.vti.sisp_sicrim.antigo.controller.programa;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;

import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm1100;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm1100B;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm1100C;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm120a;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm130a;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrp110bA;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrp110bB;
import br.com.vti.sisp_sicrim.antigo.model.DidRg;
import br.com.vti.sisp_sicrim.antigo.model.Estla001;
import br.com.vti.sisp_sicrim.antigo.model.SicCadastro;
import br.com.vti.sisp_sicrim.antigo.model.SicNumero;
import br.com.vti.sisp_sicrim.antigo.model.SicOcorrencias;
import br.com.vti.sisp_sicrim.antigo.util.ExceptionProgram;
import br.com.vti.sisp_sicrim.antigo.util.Scrg001;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe : Scrp110b OBJETIVO : INCLUSAO DA FICHA DE INDICE CRIMINAL *
 * 
 * @author Incode - Data: mai/2014
 * 
 */
@Resource
@Path("/antigo/scrp110b")
public class Scrp110b {
	// Views utilizadas
	SicCadastro criminalView = new SicCadastro();
	SicNumero numeroView = new SicNumero();
	DidRg vwdidrg = new DidRg();
	SicOcorrencias sicOcorrenciasView = new SicOcorrencias();
	// Telas/relatorios utilizados
	Scrm1100 scrm1100;
	Scrm1100B scrm1100B;
	Scrm1100C scrm1100C;
	Scrm120a scrm120a;
	Scrm130a scrm130a;
	Scrp110bA scrp110bA;
	Scrp110bB scrp110bB;
	// Includes utilizados
	Estla001 estla001 = new Estla001();
	// Areas globais / session
	Scrg001 scrg001;
	// Funcoes/subrotinas
	FuncoesGerais funcoes = new FuncoesGerais();
	Result result;
	Sessao sessao;
	Boolean primeiraVez = false;
	Scrp110b scrp110bAnterior;
	String faseproc = "0";
	// MU-FIELD
	// private String chave = "I";
	private String dmanas = "";
	private long jUltNum = 0;
	private String jMaeLimpa = "";
	private String jCrime = "";
	private int jInd1 = 0;
	private int jInd2 = 0;
	private String jDozeAster = "************";
	private long wrg = 0;
	private int var = 0;
	private String mod = "";
	private int vlt = 0;
	private String[] tabm = { "", "   ", "VEI", "CON", "MUL", "   ", "IPV", "ROU", "   ", "   ", "   ", "   ", "   ", "IDC", "ICR", "FUN", "   ", "   " };

	private Scrm1100 preMapas() {
		scrm1100 = new Scrm1100(true, sessao);
		scrm1100B = new Scrm1100B(true, sessao);
		scrm1100C = new Scrm1100C(true, sessao);
		scrm120a = new Scrm120a(true, sessao);
		scrm130a = new Scrm130a(true, sessao);
		scrp110bA = new Scrp110bA(true, sessao);
		scrp110bB = new Scrp110bB(true, sessao);
		Arrays.fill(tabm, "");
		scrm1100.setDataCorrente(UtilBean.obtemDataDia());
		scrm120a.setDataCorrente(UtilBean.obtemDataDia());
		scrm130a.setDataCorrente(UtilBean.inverteDataCorrente());
		// jContadorj = 0;
		sessao.getScrg001().setWProgramaw(this.getClass().getSimpleName());
		sessao.getScrg001().setWFuncaow("*** INCLUSAO ***          ");

		// Par�grafo: rp1()
		return scrm1100;
	}

	public Scrp110b(Result result, Sessao sessao) {
		this.result = result;
		this.sessao = sessao;
	}

	@Post
	public void executar(Scrm1100 scrm1100, Scrm1100B scrm1100B, Scrm1100C scrm1100C, Scrm120a scrm120a, Scrm130a scrm130a, Scrp110bA scrp110bA, Scrp110bB scrp110bB) {
		try {
			main(scrm1100, scrm1100B, scrm1100C, scrm120a, scrm130a, scrp110bA, scrp110bB);
		} catch (Exception e) {
			ExceptionProgram excp = new ExceptionProgram();
			excp.trataErroScrcerro(e, sessao, this.getClass().getSimpleName());
		}
	}

	private void main(Scrm1100 pscrm1100, Scrm1100B pscrm1100B, Scrm1100C pscrm1100C, Scrm120a pscrm120a, Scrm130a pscrm130a, Scrp110bA pscrp110bA, Scrp110bB pscrp110bB) throws Exception {
		if (pscrm1100 == null && pscrm1100B == null && pscrm1100C == null && pscrm120a == null && pscrm130a == null && pscrp110bA == null && pscrp110bB == null) {
			primeiraVez = true;
			// scrm1100 = new Scrm1100 (primeiraVez);
			scrm1100 = preMapas();
			scrm1100.setNavegar("../scrp110b/executar");
			result.include("scrm1100", scrm1100);
			sessao.setAtributo("SCRP110B", this);
			scrm1100.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		} else {
			restaurarEstados(pscrm1100, pscrm1100B, pscrm1100C, pscrm120a, pscrm130a, pscrp110bA, pscrp110bB);
		}
		// Repeat

		criminalView.wFunc = "INCLUSAO";

		if (pscrm1100 != null) {
			scrm1100.receberTela(false, result);
		}

		scrm120a.setJdataNasc(dmanas);
		sessao.getScrg001().setWVltw(6);
		criminalView.wChv = "*";
		if (!scrm120a.getJdataNasc().trim().equals("")) {

		}
		if (scrm1100.getJregGeral() != 0) {

		}
		if (scrm120a.getJmae() != jDozeAster) {

			jMaeLimpa = scrm120a.getJmae();
		} else {
			jMaeLimpa = "";
		}

		if (!scrm120a.getJnomecompleto().trim().equals("")) {

		}
		criminalView.wLoop += 1;
		scrm130a.setJocorrencia(1);

		criminalView.wMaoDireita = UtilBean.moveSubstring(criminalView.wMaoDireita, 0, 7, "A", scrm1100.getDedos(1, 1));
		criminalView.wMaoDireita = UtilBean.moveSubstring(criminalView.wMaoDireita, 7, 7, "A", scrm1100.getDedos(2, 1));
		criminalView.wMaoDireita = UtilBean.moveSubstring(criminalView.wMaoDireita, 14, 7, "A", scrm1100.getDedos(3, 1));
		criminalView.wMaoDireita = UtilBean.moveSubstring(criminalView.wMaoDireita, 21, 7, "A", scrm1100.getDedos(4, 1));
		criminalView.wMaoDireita = UtilBean.moveSubstring(criminalView.wMaoDireita, 28, 7, "A", scrm1100.getDedos(5, 1));

		criminalView.wMaoEsquerda = UtilBean.moveSubstring(criminalView.wMaoEsquerda, 0, 7, "A", scrm1100.getDedos(1, 2));
		criminalView.wMaoEsquerda = UtilBean.moveSubstring(criminalView.wMaoEsquerda, 7, 7, "A", scrm1100.getDedos(2, 2));
		criminalView.wMaoEsquerda = UtilBean.moveSubstring(criminalView.wMaoEsquerda, 14, 7, "A", scrm1100.getDedos(3, 2));
		criminalView.wMaoEsquerda = UtilBean.moveSubstring(criminalView.wMaoEsquerda, 21, 7, "A", scrm1100.getDedos(4, 2));
		criminalView.wMaoEsquerda = UtilBean.moveSubstring(criminalView.wMaoEsquerda, 28, 7, "A", scrm1100.getDedos(5, 2));

		// Par�grafo: fd33()

		criminalView.consultaRegEstadualGeral(scrm1100.getJregGeral());
		if (criminalView.registrosProcessados() > 0)
		// && S-MAOESQ = #MAO-ESQUERDA)
		{
			// dao.rollback();
			if (criminalView.getStatusReg() == 5) {
				scrm1100.enviarMensagem(null, "ESTA FICHA ESTA� EXCLUIDA - NAO PODE SER ALTERADA");
				result.include("scrm1100", scrm1100);
				sessao.setAtributo("SCRP110B", this);
				scrm1100.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			} else {
				scrm1100.enviarMensagem(null, "FICHA CRIMINAL JA� CADASTRADA - CONSULTE-A");
				result.include("scrm1100", scrm1100);
				sessao.setAtributo("SCRP110B", this);
				scrm1100.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
		}
		if (criminalView.registrosProcessados() == 0) {
			// Par�grafo: fd34()
			criminalView.consultaMaoDireitaMaoEsquerda(
			// jMaoDireita,
			scrm1100.getDedos(1, 1), scrm1100.getDedos(2, 1), scrm1100.getDedos(3, 1), scrm1100.getDedos(4, 1), scrm1100.getDedos(5, 1),
			// jMaoEsquerda
			scrm1100.getDedos(1, 2), scrm1100.getDedos(2, 2), scrm1100.getDedos(3, 2), scrm1100.getDedos(4, 2), scrm1100.getDedos(5, 2));
			if (jCrime.trim().equals("")) {
				jCrime = "*";
				scrm1100.enviarMensagem(null, "Formula Datil. Ja�Cadastrada Anteriormente.Consulte-a ou- Tecle <ENTER> p/ Cont.");
				return;
			}
			if (scrm1100.getJregGeral() == 0) {
				scrm120a.setJregGeral(jUltNum);
			}

			if (scrm120a.getEnviada()) {
				result.include("scrm120a", scrm120a);
				sessao.setAtributo("SCRP110B", this);
				scrm120a.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (pscrm120a != null) {
				scrm120a.receberTela(false, result);
			}
			if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
				result.include("scrm1100", scrm1100);
				sessao.setAtributo("SCRP110B", this);
				scrm1100.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			if (scrm130a.getEnviada()) {
				result.include("scrm130a", scrm130a);
				sessao.setAtributo("SCRP110B", this);
				scrm130a.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (pscrm130a != null) {
				scrm130a.receberTela(false, result);
			}
			if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
				Scrp110a scrp110a = new Scrp110a(result, sessao);
				scrp110a.executar(null, null, null, null, null, null);
				return;
			}

			criminalView.wData_atu = UtilBean.obtemDataCorrente();
			//

			criminalView.wHora = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 0, 2));
			criminalView.wMin = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 3, 2));
			criminalView.wSeg = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 6, 2));
			criminalView.wNse = Integer.parseInt(UtilBean.subStr(criminalView.wTempo, 9, 1));

			criminalView.wData_nasc0 = scrm1100.getDataNasc();

			criminalView.wData_nasc0 = UtilBean.subStr(scrm1100.getDataNasc(), 4, 4) + UtilBean.subStr(scrm1100.getDataNasc(), 2, 2) + UtilBean.subStr(scrm1100.getDataNasc(), 0, 2);
			criminalView.wDataRegistro0 = (int) UtilBean.extraiDigitos(criminalView.wDataRegistro, 8, 5, 4) * 10000 + (int) UtilBean.extraiDigitos(criminalView.wDataRegistro, 8, 3, 2) * 100 + (int) UtilBean.extraiDigitos(criminalView.wDataRegistro, 8, 1, 2);
			if (scrm120a.getJmae().equals("*")) {
				scrm120a.setJmae(jDozeAster);
			}
			if (scrm120a.getJpai().equals("*") || scrm120a.getJpai().trim().equals("")) {
				scrm120a.setJpai(jDozeAster);
			}
			for (jInd1 = 1; jInd1 <= 4; jInd1++) {
				if (scrm120a.getJalcunha(jInd1).trim().equals("") || scrm120a.getJalcunha(jInd1).equals("*")) {
					scrm120a.setJalcunha(jInd1, jDozeAster);
				}
			}
			if (scrm120a.getJnomeanterior().trim().equals("") || scrm120a.getJnomeanterior().equals("*")) {
				scrm120a.setJnomeanterior(jDozeAster);
			}
			if (scrm120a.getJnaturalidade().equals("*")) {
				scrm120a.setJnaturalidade(jDozeAster);
			}
			if (scrm120a.getJdocapresentado().equals("*")) {
				scrm120a.setJdocapresentado(jDozeAster);
			}
			if (scrm120a.getJavrua().equals("*")) {
				scrm120a.setJavrua(jDozeAster);
			}
			if (scrm120a.getJbairro().equals("*")) {
				scrm120a.setJbairro(jDozeAster);
			}
			if (scrm120a.getJcomplemento().trim().equals("") || scrm120a.getJcomplemento().equals("*")) {
				scrm120a.setJcomplemento(jDozeAster);
			}
			if (scrm130a.getJsinais().equals("*")) {
				scrm130a.setJsinais(jDozeAster);
			}
			if (scrm130a.getJnomevitima().equals("*")) {
				scrm130a.setJnomevitima(jDozeAster);
			}
			if (Integer.parseInt(scrm120a.getJdataatuacao()) < 1) {
				scrm120a.setJdataatuacao("0");
			}
			if (scrm120a.getJnoautos() < 1) {
				scrm120a.setJnoautos(0);
			}
			if (scrm120a.getJnumero() < 1) {
				scrm120a.setJnumero(0);
			}
			if (scrm120a.getJnumdocapresentado() < 1) {
				scrm120a.setJnumdocapresentado(0);
			}
			if (scrm120a.getJcodmunnascimento() < 1) {
				scrm120a.setJcodmunnascimento(0);
			}
			if (scrm120a.getJufnascimento().trim().equals("")) {
				scrm120a.setJufnascimento("**");
			}
			if (scrm120a.getJcep() < 1) {
				scrm120a.setJcep(0);
			}
			if (scrm120a.getJmunendereco() < 1) {
				scrm120a.setJmunendereco(0);
			}
			if (scrm120a.getJufendereco().trim().equals("")) {
				scrm120a.setJufendereco("**");
			}
			if (scrm120a.getJprofissao().equals("*") || scrm120a.getJprofissao().trim().equals("")) {
				scrm120a.setJprofissao(jDozeAster);
			}
			if (scrm120a.getJorgaoexpuf().equals("*") || scrm120a.getJorgaoexpuf().trim().equals("")) {
				scrm120a.setJorgaoexpuf(jDozeAster);
			}
			criminalView.setPossuiMandatoAberto(scrm1100.getJpossuimandatopaberto());
			criminalView.setRegEstadualGeral(scrm120a.getJregGeral());
			criminalView.setRegFederalCi(scrm120a.getJidentidade());
			criminalView.setStatusReg(criminalView.wStatus0);
			criminalView.setTipoReg("IN");
			criminalView.setNomeCompleto(scrm120a.getJnomecompleto());
			criminalView.setNomePai(scrm120a.getJpai());
			criminalView.setNomeMae(scrm120a.getJmae());
			criminalView.setDataNasc(criminalView.wData_nasc00);
			criminalView.setPolegarDireito(scrm1100.getDedos(1, 1));
			criminalView.setIndicadorDireito(scrm1100.getDedos(2, 1));
			criminalView.setMedioDireito(scrm1100.getDedos(3, 1));
			criminalView.setAnularDireito(scrm1100.getDedos(4, 1));
			criminalView.setMinimoDireito(scrm1100.getDedos(5, 1));
			criminalView.setPolegarEsquerdo(scrm1100.getDedos(1, 2));
			criminalView.setIndicadorEsquerdo(scrm1100.getDedos(2, 2));
			criminalView.setMedioEsquerdo(scrm1100.getDedos(3, 2));
			criminalView.setAnularEsquerdo(scrm1100.getDedos(4, 2));
			criminalView.setMinimoEsquerdo(scrm1100.getDedos(5, 2));
			criminalView.setDataDocAtu(criminalView.wData_atu);
			criminalView.setHoraAtu(criminalView.wHora_atu);
			criminalView.setMatriculaFuncAtu(sessao.getScrg001().getWMatriculaw());
			criminalView.setNomeDelegacia(scrm120a.getJdelegacia());
			criminalView.setMunicipioRegGeral(scrm120a.getJdescmunicipio());
			criminalView.setCodigoMunicipioRegGeral(scrm120a.getJmunicipio());
			criminalView.setUfRegEstadualGeral(scrm120a.getJufreggeral());
			criminalView.setDataReg(criminalView.wDataRegistro0);
			criminalView.setNumeroAutos(scrm120a.getJnoautos());
			criminalView.setDataAtuacao(Integer.parseInt(scrm120a.getJdataatuacao()));
			criminalView.setNomeAnterior(scrm120a.getJnomeanterior());
			criminalView.setApelidoAlcunhas(scrm120a.getJalcunha());
			criminalView.setSexo(scrm120a.getJsexo());
			criminalView.setNaturalidade(scrm120a.getJnaturalidade());
			criminalView.setCodigoMunicipioNasc(scrm120a.getJcodmunnascimento());
			criminalView.setUfNaturalidade(scrm120a.getJufnascimento());
			criminalView.setDocumentoApresent(scrm120a.getJdocapresentado());
			criminalView.setNumDocumentoApresent(scrm120a.getJnumdocapresentado());
			criminalView.setOrgaoExpUfUfUf(scrm120a.getJorgaoexpuf());
			criminalView.setProfissao(scrm120a.getJprofissao());
			criminalView.setGrauInstrucao(scrm120a.getJinstrucao());
			criminalView.setAvRua(scrm120a.getJavrua());
			criminalView.setNumero(scrm120a.getJnumero());
			criminalView.setBairro(scrm120a.getJbairro());
			criminalView.setMunicipio(scrm120a.getJmunendereco());
			criminalView.setEstado(scrm120a.getJufendereco());
			criminalView.setCep(scrm120a.getJcep());
			criminalView.setComplemento(scrm120a.getJcomplemento());
			criminalView.setAltura(criminalView.wAltura0);
			criminalView.setEstadoCivil(criminalView.wEstadoCivil0);
			criminalView.setCodigoCutis(criminalView.wCutis0);
			criminalView.setCodigoCorCabelo(criminalView.wCorCabelo0);
			criminalView.setCodigoTipoCabelo(criminalView.wTipoCabelo0);
			criminalView.setCodigoCorOlhos(criminalView.wCorOlhos0);
			criminalView.setMarcaPartCicatTatuag(scrm130a.getJsinais());
			criminalView.setCompleicao(criminalView.wCompleicao0);
			criminalView.setNomeVitima(scrm130a.getJnomevitima());
			criminalView.setMotivoPrisaoLei(scrm130a.getJmotivo());
			criminalView.setCpf(scrm120a.getJcpf());

			sicOcorrenciasView.setArtigoOcorr(scrm130a.getJartigo());
			sicOcorrenciasView.setIncisoOcorr(scrm130a.getJinciso());
			sicOcorrenciasView.setAlineaOcorr(scrm130a.getJalinea());
			sicOcorrenciasView.setParagrafoOcorr(scrm130a.getJparagrafo());
			sicOcorrenciasView.setLeiOcorr(scrm130a.getJlei());
			sicOcorrenciasView.setAnoLeiOcorr(scrm130a.getJanolei());
			if (scrm130a.getJobservacoes(1).trim().equals("")) {
				if (criminalView.wChv.equals("*")) {
					criminalView.wChv = "";
					scrm130a.enviarMensagem(null, "Nenhuma ocorrencia foi informada.Se nao quiser- informar Tecle<ENTER>p/confirmar");
					return;
				}
			}
			gravaOcorrencias();
			criminalView.setObservacao(criminalView.wObservacoez);
			sicOcorrenciasView.setIncidenciasCriminaisOcorr(criminalView.wObsocorr);
			ultimoRegistro();

			funcoes.phonNome = scrm120a.getJnomecompleto();
			// Fonetizacao dos campos.
			// Phonet phonet = new Phonet ();
			funcoes.phonet(funcoes.phonArea);
			criminalView.setNomeCompletoPhon(funcoes.phonComb, 1, 168);
			if (scrm120a.getJmae() != jDozeAster) {
				funcoes.phonNome = scrm120a.getJmae();
				// Phonet phonet = new Phonet ();
				funcoes.phonet(funcoes.phonArea);
				criminalView.setNomeMaePhon(funcoes.phonComb, 1, 155);
			}
			if (scrm120a.getJpai() != jDozeAster) {
				funcoes.phonNome = scrm120a.getJpai();
				// Phonet phonet = new Phonet ();
				funcoes.phonet(funcoes.phonArea);
				criminalView.setNomePaiPhon(funcoes.phonComb, 1, 150);
			}
			for (jInd1 = 1; jInd1 <= 4; jInd1++) {
				if (scrm120a.getJalcunha(jInd1) != jDozeAster) {
					funcoes.phonNome = scrm120a.getJalcunha(jInd1);
					// Phonet phonet = new Phonet ();
					funcoes.phonet(funcoes.phonArea);
					jInd2 = jInd1 * 42;
					criminalView.setApelidoAlcunhasPhon(funcoes.phonComb, 1, 42);
				}
			}

		}

		if (!scrp110bA.getEnviada()) // CONFIRMACAO
		{
			result.include("scrp110bA", scrp110bA);
			sessao.setAtributo("SCRP110B", this);
			scrp110bA.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		if (pscrp110bA != null) {
			scrp110bA.receberTela(false, result);
		}

		if (!(UtilBean.funcao.equals(UtilBean.ctt_retorna) || UtilBean.funcao.equals(UtilBean.ctt_processa))) {
			scrp110bA.enviarMensagem(null, "Tecla invalida");
			result.include("scrp110bA", scrp110bA);
			sessao.setAtributo("SCRP110B", this);
			scrp110bA.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
			Scrp110a scrp110a = new Scrp110a(result, sessao);
			scrp110a.executar(null, null, null, null, null, null);
			return;
		}
		if (scrp110bA.getJconf().trim().equals("")) {
			scrp110bA.enviarMensagem("jConf", "CONFIRME �S� OU �N�");
			result.include("scrp110bA", scrp110bA);
			sessao.setAtributo("SCRP110B", this);
			scrp110bA.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		if (!(scrp110bA.getJconf().equals("S") || scrp110bA.getJconf().equals("N"))) {
			scrp110bA.enviarMensagem("jConf", "CONFIRMACAO INVALIDA");
			result.include("scrp110bA", scrp110bA);
			sessao.setAtributo("SCRP110B", this);
			scrp110bA.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		if (scrp110bA.getJconf().equals("N")) {
			// dao.rollback();
			Scrp110a scrp110a = new Scrp110a(result, sessao);
			scrp110a.executar(null, null, null, null, null, null);
			return;
		} else {
			if (criminalView.wLoop == 1) {
				if (!scrp110bB.getEnviada()) // MATRICULA / SENHA
				{
					result.include("scrp110bB", scrp110bB);
					sessao.setAtributo("SCRP110B", this);
					scrp110bB.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
					return;
				}
				if (pscrp110bB != null) {
					scrp110bB.receberTela(false, result);
				}
				if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
					// dao.rollback();
					Scrp110a scrp110a = new Scrp110a(result, sessao);
					scrp110a.setMensagem("ATUALIZACAO NAO CONFIRMADA - TECLE <ENTER>");
					scrp110a.executar(null, null, null, null, null, null);
					return;
				}
				if (scrp110bB.getJmat() == 0) {
					scrp110bB.enviarMensagem("jMat", "INFORME A MATRICULA");
					result.include("scrp110bB", scrp110bB);
					sessao.setAtributo("SCRP110B", this);
					scrp110bB.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
					return;
				}
				if (scrp110bB.getJmat() != sessao.getScrg001().getWMatriculaw()) {
					scrp110bB.enviarMensagem("jMat", "MATRICULA NAO CORRESPONDE A MATRICULA INICIAL");
					result.include("scrp110bB", scrp110bB);
					sessao.setAtributo("SCRP110B", this);
					scrp110bB.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
					return;
				}
				if (scrp110bB.getJsenha().trim().equals("")) {
					scrp110bB.enviarMensagem("jSenha", "INFORME A SENHA");
					result.include("scrp110bB", scrp110bB);
					sessao.setAtributo("SCRP110B", this);
					scrp110bB.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
					return;
				}
				if (scrp110bB.getJsenha() != sessao.getScrg001().getWSenhaw()) {
					scrp110bB.enviarMensagem("jSenha", "SENHA NAO CORRESPONDE A SENHA INICIAL");
					result.include("scrp110bB", scrp110bB);
					sessao.setAtributo("SCRP110B", this);
					scrp110bB.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
					return;
				}
				ultimoRegistro();

				scrm1100.setMensagem("REGISTRO INCLUIDO COM SUCESSO - TECLE <ENTER>");
				// END TRANSACTION
				dmanas = "";
				for (int i1 = 1; i1 <= 5; i1++) {
					for (int i2 = 1; i2 <= 2; i1++) {
						criminalView.dedos[i1][i2] = "";
					}
				}
				jCrime = "";
			} else {
				ultimoRegistro();

				scrm1100.setMensagem("REGISTRO INCLUIDO COM SUCESSO<br>TECLE <ENTER>");
				dmanas = "";
				for (int i1 = 1; i1 <= 5; i1++) {
					for (int i2 = 1; i2 <= 2; i1++) {
						criminalView.dedos[i1][i2] = "";
					}
				}
				jCrime = "";
			}
		}

		criminalView.wChave = "";
		criminalView.wText = "";
		jCrime = "";
		scrm1100.setJregGeral(wrg);
		scrm1100.setJdisprg("<== ULTIMO REGISTRO GRAVADO");
		sessao.setAtributo("SCRP110B", this);
		result.include("scrm1100", scrm1100);
		scrm1100.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
	}

	// RESET #VARIAVEIS #CHAVE
	private void gravaOcorrencias() {
		int ind = 0;
		criminalView.wI = 1;
		if (!scrm130a.getJobservacoes(1).trim().equals(""))
		// SET KEY ALL
		{
			if (!((UtilBean.funcao.equals(UtilBean.ctt_retorna) || UtilBean.funcao.equals(UtilBean.ctt_processa)))) {
				scrm130a.enviarMensagem(null, "Tecla invalida");
				return;
			}
			for (ind = 2; ind <= 40; ind++) {
				scrm130a.setJocorrencia(ind);
				if (scrm130a.getJocorrencia() == 2) {
					criminalView.wJ = scrm130a.getJocorrencia();
					criminalView.wL = scrm130a.getJocorrencia() + 1;
					criminalView.wM = scrm130a.getJocorrencia() + 2;
					criminalView.wN = scrm130a.getJocorrencia() + 3;
					criminalView.wO = scrm130a.getJocorrencia() + 4;
				} else {
					criminalView.wI = criminalView.wM + 1;
					criminalView.wJ = criminalView.wM + 2;
					criminalView.wL = criminalView.wM + 3;
					criminalView.wM = criminalView.wM + 4;
					criminalView.wN = criminalView.wM + 5;
					criminalView.wO = criminalView.wM + 6;
				}
				criminalView.wObservacoez[criminalView.wI] = scrm130a.getJobservacoes(1);
				criminalView.wObservacoez[criminalView.wJ] = scrm130a.getJobservacoes(2);
				criminalView.wObservacoez[criminalView.wL] = scrm130a.getJobservacoes(3);
				criminalView.wObservacoez[criminalView.wM] = scrm130a.getJobservacoes(4);
				criminalView.wObservacoez[criminalView.wN] = scrm130a.getJobservacoes(5);
				criminalView.wObservacoez[criminalView.wO] = scrm130a.getJobservacoes(6);
				criminalView.wObsocorr[1] = scrm130a.getJobservacoes(1);
				criminalView.wObsocorr[2] = scrm130a.getJobservacoes(2);
				criminalView.wObsocorr[3] = scrm130a.getJobservacoes(3);
				criminalView.wObsocorr[4] = scrm130a.getJobservacoes(4);
				criminalView.wObsocorr[5] = scrm130a.getJobservacoes(5);
				criminalView.wObsocorr[6] = scrm130a.getJobservacoes(6);
				for (int i1 = 1; i1 <= 4; i1++) {
					criminalView.wObservacoes[i1] = "";
				}
				criminalView.wArtigo = 0;
				criminalView.wInciso = "";
				criminalView.wAlinea = "";
				criminalView.wParagrafo = 0;
				criminalView.wLei = 0;
				criminalView.wAnoLei = 0;

				scrm130a.receberTela(false, result);

				// 14/01 'INCIDENCIAS CRIMINAIS N.:' #OCORRENCIA(AD=OIL)
				// 15/09 #ARTIGO
				// 15/26 #INCISO
				// 15/44 #ALINEA
				// 15/55 #PARAGRAFO
				// 15/68 #LEI
				// 15/73 #ANO-LEI
				// 16/01 ' ' #OBSERVACOES(1)(AD=AIL'_")
				// 17/01 ' ' #OBSERVACOES(2)(AD=AIL'_")
				// 18/01 ' ' #OBSERVACOES(3)(AD=AIL'_")
				// 19/01 ' ' #OBSERVACOES(4)(AD=AIL'_")
				// 20/01 ' ' #OBSERVACOES(5)(AD=AIL'_")
				// 21/01 ' ' #OBSERVACOES(6)(AD=AIL'_")
				if (!((UtilBean.funcao.equals(UtilBean.ctt_retorna) || UtilBean.funcao.equals(UtilBean.ctt_processa)))) {
					scrm130a.enviarMensagem(null, "Tecla invalida");
					return;
				}

				if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
					Scrp110a scrp110a = new Scrp110a(result, sessao);
					scrp110a.executar(null, null, null, null, null, null);
					return;
				}
				for (criminalView.wX = 4; criminalView.wX >= 2; criminalView.wX += -1) {
					if (!scrm130a.getJobservacoes(criminalView.wX).trim().equals("")) {
						criminalView.wW = criminalView.wX - 1;
						for (criminalView.wY = criminalView.wW; criminalView.wY >= 1; criminalView.wY += -1) {
							if (scrm130a.getJobservacoes(criminalView.wY).trim().equals("")) {
								scrm130a.enviarMensagem(null, "");
								return;
							}
						}
					}
				}
				if (scrm130a.getJobservacoes(1).trim().equals("")) {
					break;
				}
			}
		}
	}

	private void verStatus() {
		switch (criminalView.wStatus0) {
		case 1: {
			scrm120a.setJdescreg("Registro Normal");
			break;
		}
		case 2: {
			scrm120a.setJdescreg("Registro Cancelado");
			break;
		}
		case 3: {
			scrm120a.setJdescreg("REGISTRO COM MANDATO DE PRISAO");
			break;
		}
		case 4: {
			scrm120a.setJdescreg("Condenado");
			break;
		}
		default: {
			break;
		}
		}
	}

	private void ultimoRegistro() {

		while (numeroView.leitura()) {

			numeroView.setUltimoNumero(numeroView.getUltimoNumero());
			numeroView.setUltimoNumero(1L);
			wrg = numeroView.getUltimoNumero();
			numeroView.atualiza();

		}

		criminalView.setRegEstadualGeral(wrg);
		criminalView.grava();
		// dao.commit();
		while (sicOcorrenciasView.pesquisaRegEstadualGeralOcorr(wrg)) {

			sicOcorrenciasView.setRegEstadualGeralOcorr(wrg);
			sicOcorrenciasView.atualiza();
			// dao.commit();
		}
		if (sicOcorrenciasView.registrosProcessados() == 0) {
			sicOcorrenciasView.setRegEstadualGeralOcorr(wrg);
			sicOcorrenciasView.grava();
			// dao.commit();
		}
		// ATUALIZA DID-RG REGISTROS PARA ABN
		vwdidrg.consultaNumeroRg(scrm1100.getJregGeral());
		vwdidrg.setNumeroRg(wrg);
		vwdidrg.setDataAtualizacao(UtilBean.obtemDataCorrente());
		vwdidrg.setHoraAtualizacao(Integer.parseInt((new SimpleDateFormat("HHmmssS").format(Calendar.getInstance().getTime()))));
		// abnFlag = "";
		vwdidrg.atualiza();
		// dao.commit();
		// dao.rollback();
		if (vwdidrg.registrosProcessados() == 0) {
			vwdidrg.setNumeroRg(wrg);
			vwdidrg.setDataAtualizacao(UtilBean.obtemDataCorrente());
			vwdidrg.setHoraAtualizacao(Integer.parseInt((new SimpleDateFormat("HHmmssS").format(Calendar.getInstance().getTime()))));
			// abnFlag = "";
			vwdidrg.grava();
			// dao.commit();
		}
		// ATUALIZA SIC-ESTATISTICAS NO CRIMINAL

		estla001.cpo = 01;
		estla001.qde = 01;
		// INCLUS�O

		sessao.getSisgsisp().setVlt(14);
		sessao.getSisgsisp().setVar(14);
		mod = tabm[14];
		estla001.esttip = 98;
		funcoes.estna001(estla001.cpo, estla001.esttip, estla001.qde, var, sessao.getScrg001().getWMatriculaw());
	}

	private void restaurarEstados(Scrm1100 pscrm1100, Scrm1100B pscrm1100B, Scrm1100C pscrm1100C, Scrm120a pscrm120a, Scrm130a pscrm130a, Scrp110bA pscrp110bA, Scrp110bB pscrp110bB) {
		this.scrp110bAnterior = (Scrp110b) sessao.getAtributo("SCRP110B");
		if (pscrm1100 != null) {
			scrm1100 = pscrm1100;
		} else {
			scrm1100 = this.scrp110bAnterior.scrm1100;
		}
		scrm1100.setSessao(sessao);
		if (pscrm1100B != null) {
			scrm1100B = pscrm1100B;
		} else {
			scrm1100B = this.scrp110bAnterior.scrm1100B;
		}
		scrm1100B.setSessao(sessao);
		if (pscrm1100C != null) {
			scrm1100C = pscrm1100C;
		} else {
			scrm1100C = this.scrp110bAnterior.scrm1100C;
		}
		scrm1100C.setSessao(sessao);
		if (pscrm120a != null) {
			scrm120a = pscrm120a;
		} else {
			scrm120a = this.scrp110bAnterior.scrm120a;
		}
		scrm120a.setSessao(sessao);
		if (pscrm130a != null) {
			scrm130a = pscrm130a;
		} else {
			scrm130a = this.scrp110bAnterior.scrm130a;
		}
		scrm130a.setSessao(sessao);
		if (pscrp110bA != null) {
			scrp110bA = pscrp110bA;
		} else {
			scrp110bA = this.scrp110bAnterior.scrp110bA;
		}
		scrp110bA.setSessao(sessao);
		if (pscrp110bB != null) {
			scrp110bB = pscrp110bB;
		} else {
			scrp110bB = this.scrp110bAnterior.scrp110bB;
		}
		scrp110bB.setSessao(sessao);
		this.faseproc = this.scrp110bAnterior.faseproc;
	}
}
